<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('修改医生管理')" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-doctor-edit" th:object="${doctor}" autocomplete="off">
            <input name="id" th:field="*{id}" type="hidden">
            <div class="form-group">
                <label class="col-sm-3 control-label is-required">医生姓名：</label>
                <div class="col-sm-8">
                    <input name="name" th:field="*{name}" class="form-control" readonly type="text" >
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label is-required">医生电话：</label>
                <div class="col-sm-8">
                    <input name="phone" th:field="*{phone}" class="form-control" readonly type="text" >
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label is-required">佣金余额：</label>
                <div class="col-sm-8">
                    <input name="balance" id="balance" th:field="*{balance}" class="form-control" readonly type="text" >
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label is-required">返佣金额：</label>
                <div class="col-sm-8">
                    <input name="kickback" id="kickback" th:field="*{kickback}"
                           oninput="input_num(this)"
                           class="form-control"  type="number" required>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">备注：</label>
                <div class="col-sm-8">
                    <textarea name="remark" class="form-control">[[*{remark}]]</textarea>
                </div>
            </div>
        </form>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
        var prefix = ctx + "info/doctor";
        $("#form-doctor-edit").validate({
            focusCleanup: true
        });

        // 格式化限制数字文本框输入，只能数字或者两位小数
        function input_num(obj){
            // 清除"数字"和"."以外的字符
            obj.value = obj.value.replace(/[^\d.]/g,"");
            // 验证第一个字符是数字
            obj.value = obj.value.replace(/^\./g,"");
            // 只保留第一个, 清除多余的
            obj.value = obj.value.replace(/\.{2,}/g,".");
            obj.value = obj.value.replace(".","$#$").replace(/\./g,"").replace("$#$",".");
            // 只能输入两个小数
            obj.value = obj.value.replace(/^(\-)*(\d+)\.(\d\d).*$/,'$1$2.$3');

            //如果有小数点，不能为类似 1.10的金额
            if(obj.value.indexOf(".")> 0  && obj.value.indexOf("0")>2){
                obj.value= parseFloat(obj.value);
            }
            //如果有小数点，不能为类似 0.00的金额
            if(obj.value.indexOf(".")> 0  && obj.value.lastIndexOf("0")>2){
                obj.value= parseFloat(obj.value);
            }
            //以上已经过滤，此处控制的是如果没有小数点，首位不能为类似于 01、02的金额
            if (obj.value.indexOf(".") <= 0 && obj.value != "") {
                obj.value = parseFloat(obj.value);
            }
        }
        function submitHandler() {
            if ($.validate.form()) {
                var config = {
                    url: prefix + "/pay",
                    type: "post",
                    dataType: "json",
                    data: $('#form-doctor-edit').serialize(),
                    beforeSend: function () {
                        $.modal.loading("正在处理中，请稍候...");
                        $.modal.disable();
                    },
                    success: function(result) {
                        parent.$.treeTable.refresh();
                    }
                };
                $.ajax(config)
            }
        }
    </script>
</body>
</html>
